package com.achievement.controller;

import com.achievement.domain.dto.AppraisalProductDTO;
import com.achievement.domain.param.AppraisalProductParam;
import com.achievement.domain.vo.AppraisalProductVO;
import com.achievement.service.IAppraisalProductService;
import com.common.annotation.Anonymous;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * 科研成果-鉴定成果列Controller
 *
 * @date 2025-02-27
 */

@RestController
@RequestMapping("/achievement/appraisal")
@Api(tags = "成果管理模块---鉴定成果管理")
public class AppraisalProductController extends BaseController {
    @Autowired
    private IAppraisalProductService AppraisalProductService;

    /**
     * 查询科研成果-鉴定成果列列表
     */
    @PreAuthorize("@ss.hasPermi('achievement:appraisalProduct:list')")
    @ApiOperation(value = "查询科研成果-鉴定成果列列表",notes = "查询科研成果-鉴定成果列列表")
    @GetMapping("/list")
    public TableDataInfo list(AppraisalProductParam param) {
        startPage();
        List<AppraisalProductVO> list =
                AppraisalProductService.selectByPage(param);
        return getDataTable(list);
    }

    /**
     * 左上方统计 通过，退回，待审核
     * @param param 检索参数
     * @return AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('achievement:appraisalProduct:list')")
    @ApiOperation(value = "左上方统计 通过，退回，待审核",notes = "左上方统计 通过，退回，待审核")
    @GetMapping(value = "/list-statistics")
    public AjaxResult listStatistics(AppraisalProductParam param)
    {
        List<HashMap<String, Integer>> list =AppraisalProductService.listStatistics(param);

        return success(list);
    }

    /**
     * 导出科研成果-鉴定成果列列表
     */
    @PreAuthorize("@ss.hasPermi('achievement:appraisalProduct:export')")
    @Log(title = "科研成果-鉴定成果列", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "导出科研成果-鉴定成果列列表",notes = "导出科研成果-鉴定成果列列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody  AppraisalProductParam param) {
        List<AppraisalProductVO> list =
                AppraisalProductService.getListByConditions(param);
        List<String> selectedColumns = param.getExcelColumn();
        ExcelUtil<AppraisalProductVO> util = new ExcelUtil<>(AppraisalProductVO.class);
        util.showColumn(selectedColumns.toArray(new String[0]));
        util.exportExcelByOrder(response, list, "科研成果-鉴定成果列数据",selectedColumns.toArray(new String[0]));
    }

    /**
     * 获取科研成果-鉴定成果列详细信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:appraisalProduct:query')")
    @GetMapping(value = "/{ID}")
    @ApiOperation(value = "获取科研成果-鉴定成果列详细信息",notes = "获取科研成果-鉴定成果列详细信息")
    public AjaxResult getInfo(@PathVariable("ID") String ID) {
        return success(AppraisalProductService.getInfoById(ID));
    }

    /**
     * 新增科研成果-鉴定成果列
     */
    @PreAuthorize("@ss.hasPermi('achievement:appraisalProduct:add')")
    @Log(title = "科研成果-鉴定成果列", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增科研成果-鉴定成果列",notes = "新增科研成果-鉴定成果列")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody AppraisalProductDTO dto) {
        return AppraisalProductService.add(dto);
    }

    /**
     * 修改科研成果-鉴定成果列
     */
    @PreAuthorize("@ss.hasPermi('achievement:appraisalProduct:edit')")
    @Log(title = "科研成果-鉴定成果列", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改科研成果-鉴定成果列",notes = "修改科研成果-鉴定成果列")
    @PostMapping(value = "/update")
    public AjaxResult edit(@RequestBody AppraisalProductDTO dto) {
        return AppraisalProductService.update(dto);
    }

    /**
     * 删除科研成果-鉴定成果列
     */
    @PreAuthorize("@ss.hasPermi('achievement:appraisalProduct:remove')")
    @Log(title = "科研成果-鉴定成果列", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除鉴定成果",notes = "删除鉴定成果")
    @DeleteMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids) {
        return toAjax(AppraisalProductService.deleteAppraisalProductByIDs(ids));
    }
}
